using UnityEngine;
using QFramework;

namespace ProjectChildhood
{
	public partial class UIMessageQueue : ViewController
	{
		public static void Push(Sprite icon, string message)
		{
            m_Instance.mq_templete.InstantiateWithParent(m_Instance.mq_root_list.transform)
                .Self(self =>
                {
                    self.icon.sprite = icon;
                    self.icon.gameObject.SetActive(icon != null);
                    self.text_message.gameObject.SetActive(icon != null);
                    self.text_message_single.gameObject.SetActive(icon == null);
                    self.text_message.text = self.text_message_single.text = message;
                    
                    self.SetAlpha(0);
                    self.Show();
                    ActionKit.Sequence()
                        .Lerp(0, 1, 0.5f, self.SetAlpha)
                        .Delay(3.0f)
                        .Lerp(1, 0, 2.0f, self.SetAlpha)
                        .Start(self, () => { self.DestroyGameObj(); });
                });
		}

		private static UIMessageQueue m_Instance;
		public static UIMessageQueue Instance => m_Instance ;

        private void Awake()
        {
            m_Instance = this;
            mq_templete.Hide();
        }

        private void OnDestroy()
        {
            m_Instance = null;
        }
    }
}
